package com.hc.dao;

import com.hc.bean.Pager;
import com.hc.bean.Product;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface ProductDao {
    /*商品添加*/
    @Insert("insert into product values(null,#{productName},#{productPrice},#{productStock},#{productPicture},#{productType}," +
            "#{productState},#{productIntroduction})")
    @Options(useGeneratedKeys = true,keyProperty = "productId",keyColumn = "productId")
    Integer addProduct(Product product);

    /*商品修改*/

    /*商品上下架*/

    /*模糊查询*/
    @Select("<script>" +
            " select * from product " +
            " <if test='productName!= null'>" +
            " <where>" +
            " productName like concat('%',#{productName},'%') " +
            " </where>" +
            " </if>" +
            " </script>")
    List<Product> fuzzyQuery(Product product);

    /*模糊分页查询*/
    /*多个参数要使用@Param注解*/
    @Select("<script>" +
            " select * from product " +
            " <if test='product.productName!= null'>" +
            " <where>" +
            " productName like concat('%',#{product.productName},'%') " +
            " </where>" +
            " </if>" +
            " limit #{pager.firstLimitParam},#{pager.pageRows}" +
            " </script>")
    List<Product> fuzzyPagingQuery(@Param("product") Product product, @Param("pager") Pager pager);

    /*根据id查询商品信息*/
    @Select("select * from product where productId=#{pid}")
    Product getProductById(Integer pid);
}
